package com.flyxteam.commons.httpclient;

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.Cookie;

public class Main {
	public static void main(String[] args) {
		try {
			String url = "http://127.0.0.1:8081/DemoServlet/servlet";
			
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("a", 1);
			params.put("b", 2);
			params.put("c", "me");
			params.put("d", "我");
			
			Cookie[] cookies = null;
		
			HttpClientResult result = doServiceGet(url, params, cookies);
			System.out.println(result.toString());
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static HttpClientResult doServiceGet(String url, Map<String, Object> params, Cookie[] cookies) throws Exception {
		
		Map<String, Object> headers = new HashMap<String, Object>();
		
		HttpClientConfig config = null;

		// 发送HTTP请求返回数据
		HttpClientResult httpClientResult = null;
		try {
			httpClientResult = HttpClientUtil.doGet(url, params, headers, config, cookies);
		} catch (Exception e) {
			throw new HttpClientTimeoutException(e);
		}
		
		// 异常情况
		if (httpClientResult == null) {
			throw new Exception("httpClientResult == null");
		}

		
		return httpClientResult;
	}
}
